package org.jash.learnmvp.news;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import org.jash.learnmvp.entity.CategoryEntity;

import java.util.ArrayList;
import java.util.List;

public class CategoryAdapter extends FragmentStateAdapter {
    private List<CategoryEntity.DataBean> list = new ArrayList<>();
    public CategoryAdapter(@NonNull Fragment fragmentActivity) {
        super(fragmentActivity);
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        CategoryEntity.DataBean bean = list.get(position);
        return  CategoryFragment.newInstance(bean.getId(), bean.getName());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public String getTitle(int position) {
        return list.get(position).getName();
    }
    public void addAll(List<CategoryEntity.DataBean> list) {
        int size = this.list.size();
        this.list.addAll(list);
        notifyItemRangeInserted(size, list.size());
    }
}
